<?php
class PostListAction extends FrontendAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'tpl';
		$this->layout = 'index';
		$this->data['menu']		= 'post';
		$this->data['layout_class']	= 'yui-t5';
	}

	public function execute()
	{
		$con			= array('status'=>1,'pid'=>0);
		$tag			= $this->context->get('tag');
		if(is_numeric($tag) && $tag>0)
		{
			$con['tag_id']	= $tag;
			$tagInfo		= C('TagService')->get($tag);
			$this->data['tag_id']	= $tag;
		}
		$page			= $this->getPage();
		$ltConfig		= C('LtConfig');
		$pagerConfig	= $ltConfig->get('pagination.pager');
		$pageSize		= 40;
		$pagerConfig['per_page']		= $pageSize;
		$pagerConfig['num_links_show']	= 10;
		$ltConfig->addConfig(array('pagination.pager'=>$pagerConfig));
		
		$num 			= $pageSize;
		$start	 		= ($page-1) * $pageSize;
		//文章
		$postService	= new PostService();
		$result			= $postService->getList($con,'last_updated DESC',$start,$num);
		$totalNum		= $result['count'];
		$postList		= $result['rows'];
		$this->data['totalNum']		= $totalNum;
		$this->data['postList']		= $postList;
		
		$baseUrl 	= C('LtUrl')->generate('Post', 'List', array('p' => ':page','tag'=>$tag));
		
		$pagination 	= new PiscesPagination;
		$pagination->init();
		$this->data['pages'] = $pagination->pager($page, $totalNum, $baseUrl);
		
		//广告
		$adService		= new AdService();
		$adList			= $adService->getAdList(true,array('position'));
		$this->data['adList']	= $adList;
		
		if($tagInfo)
		{
			$seoTitle		= $tagInfo['name'].'-资讯中心';
		}
		else
		{
			$seoTitle		= '资讯中心';
		}
		$seoTitle		.= '-'.$page;
		$seoTitle		.= '-'.$this->data['site']['site_name'];
		
		$seoKeyword		= $seoTitle;
		$seoDescription	= $seoTitle;
		
		$this->data['seo']['title']			= $seoTitle;
		$this->data['seo']['keyword']		= $seoKeyword;
		$this->data['seo']['description']	= $seoDescription;
	}
}
